<?php
namespace Service\WebSocketService\WebSocketRouter;
use Service\BaseService;
use Service\Code\Normal;
use App\Model\PssModel\OrderSupplier;
use App\Model\PssModel\Business;
use App\Model\CommodityModel\SupplierCompany;
use App\Model\PssModel\OrderSupplierGoods;
use Service\AppService\Common;
use App\Model\CommodityModel\WarehouseInfo;
use App\Model\CommodityModel\CommodityArchives;

/**
 * 订单列表导出服务
 */
class SuppplierOrderSocketService extends BaseService
{
    public $server;
    public $fd;
    public $host;
    public $pageLimit = 2000;
    public $percent_status = [
        '1' => '写入中',
        '2' => '完成',
        '3' => '异常错误'
    ];
    
    /**
     * 需要加密的用户
     */
    public $encrptUserTag = [
        'jd'    => '京东'
    ];
    
    /**
     * 获取查询条件
     * @param array $data
     */
    public function getQuery(string $where)
    {
        $table = OrderSupplier::instance()->getTable();
        $model = OrderSupplier::instance()
        ->from("{$table} as o")
        ->leftJoin('business as b', "b.id","=","o.bid")
        ->whereRaw($where);
        return $model;
    }
    
    /**
     * 业务方法
     * @param object $server
     * @param int $fd
     * @param array $data
     * @param array $sysInfo
     * @param array $excel_hedaer
     * @param array $excel_data
     * @return mixed
     */
    public function OrderExport($server,int $fd,array $data,array $sysInfo,array $excel_hedaer,array $excel_data)
    {
        $this->server   = $server;
        $this->fd       = $fd;
        $this->sysInfo  = $sysInfo;
        
        //组装搜索条件
        $where          = $this->getSearchParam($data);
        
        //获取总条数
        $total_count = $this->getQuery($where)->count();
        
        //预估分页
        $total_page  = ceil($total_count / $this->pageLimit);
        $importData  = [];
        
        
        //导出数据
        $lastId = 0;
        $page = 1;
        while ( true )
        {
            $orderList = $this
            ->getQuery($where)
            ->select($this->getFields())
            ->where('o.id','>',$lastId)
            ->orderBy('o.id','asc')
            ->limit($this->pageLimit)
            ->get()
            ->toArray();
            if( empty($orderList))
            {
                break;
            }
        
            //处理无极分页
            $endRow = end($orderList);
            $lastId = $endRow['order_id'];
            
            $orderIds = array_column($orderList,'order_id');
            $supplierGoodsList = OrderSupplierGoods::instance()->select([
                'order_id',
                'goods_type',
                'goods_name',
                'quantity',
                'spec_num',
                'barcode',
                'costprice',
                'settlement_price',
                'price',
                'store_id',
                'yx_store_id',
                'tax_rate',
            ])
            ->whereIn('order_id',$orderIds)
            ->get()
            ->toArray();
            
            //查询是否优选仓库
            $yxStoreIds = array_filter(array_column($supplierGoodsList, 'yx_store_id'));
            if( isset($yxStoreIds[0]) ) { unset($yxStoreIds[0]);}
            $yxStoreIds = array_unique(array_keys($yxStoreIds));
            
            //获取仓库供应商信息
            $wareHouseIds = array_filter(array_unique(array_column($orderList,'store_id')));
            $wareHouseIds = array_merge($wareHouseIds,$yxStoreIds);
            $wareHouseInfo  = WarehouseInfo::instance()->getWareHouseListAllByIds($wareHouseIds);
            $wareHouseInfoMap = array_column($wareHouseInfo, null,'ID');
            
            //供应商信息
            $supplierIds    = array_filter(array_unique(array_column($wareHouseInfo, 'SupplierID')));
            $supplierInfo   = Suppliercompany::instance()->getSupplierListByIds($supplierIds);
            $supplierInfoMap = array_column($supplierInfo, null,'ID');
            
            $tmpData = [];
            
            //已商品快照作为分页数据
            $orderListMap = array_column($orderList, null,'order_id');
            foreach ($supplierGoodsList as $goodsInfo )
            {
                $item = $orderListMap[$goodsInfo['order_id']];
                $item = $this->getEncryptDataByOrderItem($item);
                $item['shipping_time']          = $item['shipping_time'] ? date('Y-m-d H:i:s',$item['shipping_time']) : '';
                $item['order_status_txt']       = OrderSupplier::instance()->order_status[$item['order_status']];
                $item['order_create_time']      = date('Y-m-d H:i:s',$item['cd']);
                $item['pay_time']               = !empty($item['pay_time']) ? date('Y-m-d H:i:s',$item['pay_time']) : '';
            
                if( isset($parameters['requestData']['isBest']) && $parameters['requestData']['isBest'] == 1 ) {
                    $storeInfo = isset($wareHouseInfoMap[$goodsInfo['yx_store_id']]) ? $wareHouseInfoMap[$goodsInfo['yx_store_id']] : [];
                } else {
                    $storeInfo = isset($wareHouseInfoMap[$goodsInfo['store_id']]) ? $wareHouseInfoMap[$goodsInfo['store_id']] : [];
                }
            
                if( !empty($storeInfo) ) {
                    $company_name = $supplierInfoMap[$storeInfo['SupplierID']]['SupplierName'] ?? '';
                    $store_name   = $storeInfo['WarehouseName'];
                } else {
                    $company_name = $store_name = '';
                }
            
                if(!empty($item['apply_extends']))
                {
                    $extends=json_decode($item['apply_extends'],1);
                    $item['enterpriseNum']=$extends['enterpriseNum']??'';
                    $item['enterpriseName']=$extends['enterpriseName']??'';
                    $item['payCommanyCode']=$extends['payCommanyCode']??'';
                    $item['payCommanyName']=$extends['payCommanyName']??'';
                    $item['innerTransactionId']=$extends['innerTransactionId']??'';
                }
            
                //计算价格
                $quantity               = $goodsInfo['quantity'];
                $total_costprice        = bcmul($goodsInfo['costprice'], $quantity,2);
                $total_settlement_price = bcmul($goodsInfo['settlement_price'], $quantity,2);
                $total_price            = bcmul($goodsInfo['price'], $quantity,2);
            
                //商品不含税价
                $tax_all                = bcadd('1.000', $goodsInfo['tax_rate'], 4);
                $noFeePrice             = bcdiv($goodsInfo['price'], $tax_all,2);
                $goods_total_money      = bcmul($noFeePrice,$quantity,2);
            
                //税费
                $tax_money              = bcsub($total_price, $goods_total_money,2);
            
                //商品预估收益
                //2020年6月28号 之前的预估收益为0，结算价=成本价
                $profit_limit_time      = strtotime('2020-06-28 23:59:59');
                if( $item['cd'] > $profit_limit_time ) {
                    $profit_money = bcsub($total_settlement_price, $total_costprice,2);
                } else {
                    $profit_money = 0.00;
                    $total_settlement_price = $total_costprice;
                }
                $rowData = [
                    $item['order_sn'],
                    $item['thirdpart_order_sn'] ? $item['thirdpart_order_sn'] : $item['supplier_csn'],
                    $item['supplier_psn'],
                    $item['supplier_dsn'],
                    $goodsInfo['goods_name'],
                    CommodityArchives::instance()->goods_types[$goodsInfo['goods_type']]??'未定义',
                    $goodsInfo['quantity'],
                    $goodsInfo['spec_num'],
                    $goodsInfo['barcode'],
                    $item['pay_sn'],
                    $item['enterpriseNum']??'',
                    $item['enterpriseName']??'',
                    $item['payCommanyCode']??'',
                    $item['payCommanyName']??'',
                    $item['innerTransactionId']??$item['supplier_dsn'],
                    $company_name,
                    $store_name,
                    $item['merchantName'],
                    $goods_total_money,
                    $tax_money,
                    $item['deliver_money'],
                    $item['discount_money'],
                    $total_price,
                    $item['real_total_money'],
                    $total_costprice,
                    $total_settlement_price,
                    $profit_money,
                    $item['order_status_txt'],
                    $item['order_create_time'],
                    $item['pay_time'],
                    $item['pay_remark'],
                    OrderSupplier::instance()->order_push_status[$item['order_push_status']]??"未定义",
                    $item['order_push_remark'],
                    $item['express_name'],
                    $item['express_sn'],
                    $item['shipping_time'],
                    $item['receive_name'],
                    $item['recveive_phone'],
                    $item['buyer_realname'],
                    $item['buyer_phone'],
                    $item['buyer_idcard'],
                    $item['receive_address'],
                    join('-',[$item['province'],$item['city'],$item['district']]),
                    $item['after_verify_status'] == 1 ? '是' : '否',
                ];
                $tmpData[] = $rowData;
            }
            
            $importData = array_merge($importData, $tmpData);
            if( $page == $total_page ) {
                $percent = 98.00;//预留给写文件使用
            } else {
                $percent = bcdiv($page, $total_page,4);
                $percent = bcmul($percent, 100,2);
            }
            
            if( $this->server ) {
                $send = Normal::returnWsStatus(Normal::WS_START,"进行中",[
                    'percent'   => $percent
                ]);
                $send = json_encode($send,JSON_UNESCAPED_UNICODE);
                $this->server->push($this->fd,$send);
            }
            
            $page++;
        }
        
        //组装数据完成
        $send = Normal::returnWsStatus(Normal::WS_START, "进行中", [
            'percent' => 99.00,
        ]);
        $this->server->push($this->fd,json_encode($send, JSON_UNESCAPED_UNICODE));
        
        //开始导出数据
        $result_export = \exportFile($this->getHeader(),$importData,'订单导出明细');
        
        $importData = [];
        
        //导出异常
        if( $result_export['code'] != Normal::SUC ) {
            return Normal::returnWsStatus(Normal::WS_ERROR, $result_export['msg']);
        }
        
        return Normal::returnWsStatus(Normal::WS_END, "已完成", [
            'percent'      => 100.00,
            'download_url' => $result_export['data']['url'],
        ]);
    }

    /**
     * 获取字段
     */
    public function getFields()
    {
        return [
            "o.id as order_id",
            "o.bid",
            "o.store_id",
            "o.company_id",
            "o.order_sn",
            "o.order_type",
            "o.supplier_psn",
            "o.supplier_csn",
            "o.supplier_dsn",
            "o.thirdpart_order_sn",
            "o.order_status",
            "o.order_push_status",
            "o.order_push_remark",
            "o.pay_remark",
            "o.real_total_money",
            "o.express_name",
            "o.express_sn",
            "o.express_shipping_time",
            "o.is_apply",
            "o.apply_remark",
            "o.after_sale_status",
            "o.after_verify_status",
            "o.order_source",
            "o.goods_money",
            "o.deliver_money",
            "o.discount_money",
            "o.total_money",
            "o.cd",
            "o.receive_name",
            "o.recveive_phone",
            "o.buyer_realname",
            "o.buyer_idcard",
            "o.buyer_phone",
            "o.province",
            "o.city",
            "o.district",
            "o.receive_address",
            "o.pay_sn",
            "o.pay_time",
            "o.apply_extends",
            "o.express_shipping_time as shipping_time",
            "o.is_encrypt_order",
            "b.name as merchantName",
            "b.user_tag",
        ];
    }

    public function getHeader()
    {
        return [
            '渠道商订单编号',
            '供应商订单编号',
            '云仓主订单编号',
            '云仓子订单编号（对接上游供应商使用）',
            '所含商品',
            '商品类型',
            '商品数量',
            '规格起售数量',
            '国际条码',
            '支付流水号',
            '电商平台海关备案号',
            '电商平台海关备案名',
            '支付企业海关备案号',
            '支付企业海关备案名称',
            '支付申报单号',
            '供应商',
            '仓库',
            '商户',
            '商品金额',
            '商品税费',
            '运费',
            '优惠金额',
            '订单金额',
            '实际支付金额',
            '采购成本',
            '商户结算金额',
            '预估利润',
            '订单状态',
            '订单创建时间',
            '支付时间',
            '支付结果',
            '供应商订单推送状态',
            '供应商订单推送结果',
            '物流公司',
            '物流单号',
            '发货时间',
            '收货人姓名',
            '收货人手机号码',
            '付款人姓名',
            '付款人手机号码',
            '身份证号码',
            '收货地址',
            '省市区',
            '是否售后'
        ];
    }

    /**
     * 订单搜索参数
     * @param array $parameters
     * @return string[]|number[]|unknown[]
     */
    public function getSearchParam(array $search)
    {
        $sysInfo = $this->sysInfo;
        
        //限制数据权限
        if( $sysInfo['account'] == 'pdduser' ) {
            $bus = Business::instance()->getUserInfoByAccount('pdd');
            $bid = $bus['bid'];
        }

        $where  = "";
        $limit  = isset($search['limit']) ? $search['limit'] : 10 ;
        $where.= 'o.df = 0';
        if( isset($bid) ) {
            $where .= " AND o.bid = {$bid}";
        } else {
            if( !empty($search['bid']) ){
                $where .= " AND o.bid = {$search['bid']}";
            }

            if( !empty($search['merchantUserIds']) ){
                $MerchantUserIds = $search['merchantUserIds'];
                if( is_array($MerchantUserIds) ) {
                    $MerchantUserIds = array_filter($MerchantUserIds);
                    $whereUserIdsIn = implode(",", $MerchantUserIds);
                    $where .= " AND o.bid IN ({$whereUserIdsIn})";
                } else {
                    $where .= " AND o.bid = {$MerchantUserIds}";
                }
            }
        }
        
        //供应商账号登录
        if( $sysInfo['is_supplier_account'] == 1 ) 
        {
            $supplier_ids = implode(",", $sysInfo['supplier_ids']);
            if( !empty($supplier_ids) ) {
                $where .= " AND o.company_id in({$supplier_ids})";
            } else {
                $where .= " AND o.company_id = 0 ";
            }
        }

        //获取超时未发货订单
        if( isset($search['noShippingOrder']) && $search['noShippingOrder'] == 1 ) {
            $current_time = time();
            $start_time = $current_time - 60*60*12;
            $where .= " AND order_status =1 AND o.after_sale_status = 0 AND o.md > 0 AND o.md <= {$start_time} ";
        }


        //支付单申报状态搜索
        if( isset($search['payDeclareStatus']) && in_array($search['payDeclareStatus'], ['0','1','2','3']) ) {
            $where .= " AND o.is_apply = {$search['payDeclareStatus']} ";
        }

        //异常订单
        if( isset($search['declareFailOrder']) && $search['declareFailOrder'] == 1 ) {
            $where .= " AND order_status =1 AND (is_apply = 2 or order_decalre_status =3 ) ";
        } else {
            // 订单来源
            if( isset($search['order_type']) && in_array($search['order_type'], ['0','1','2','3','4','5','6',SHOP_SELF_BONDED_ORDER,'10']) ){
                if( $search['order_type'] != SHOP_SELF_BONDED_ORDER ) {
                    $search['order_type'] = $search['order_type'] == 1 ? '1,2' : $search['order_type'];
                    $search['order_type'] = $search['order_type'] == '0' ? '0,3,4,5,6,10' : $search['order_type'];
                    $where .= " AND o.order_type in({$search['order_type']})";
                } else {
                    $where .= " AND o.order_type ={$search['order_type']}";
                }
            }
        }

        //云仓主订单号
        if( !empty($search['supplier_psn']) ){
            $where .= " AND o.supplier_psn = '{$search['supplier_psn']}'";
        }

        //订单类型
        if( isset($search['isBest']) && $search['isBest'] == 1 ) {
            $search['company_type'] = ['2'] ;
        }

        if( !empty($search['company_type']) ){
            $company_types = array_filter($search['company_type']);
            if($company_types) {
                $company_type = implode(",",$company_types);
                $where .= " AND o.company_type in({$company_type})";
            }
        }

        //供应商订单号
        if( !empty($search['supplier_csn']) ){
            $where .= " AND o.supplier_csn = '{$search['supplier_csn']}'";
        }

        //云仓子单号
        if( !empty($search['supplier_dsn']) ){
            $where .= " AND o.supplier_dsn = '{$search['supplier_dsn']}'";
        }

        //商户订单号
        if( !empty($search['order_sn']) ){
            $where .= " AND o.order_sn = '{$search['order_sn']}'";
        }

        //审核订单状态
        if( isset($search['after_verify_status']) && isset(OrderSupplier::instance()->after_verify_status[$search['after_verify_status']]) ){
            //待审核
            if( $search['after_verify_status'] == 0 ) {//待审核
                $where .= " AND o.after_verify_status = 0 AND o.after_sale_status = 1";
            } else if( $search['after_verify_status'] == 1 ) {//审核通过
                $where .= " AND (o.after_verify_status = 1 or (o.after_sale_status = 1 and order_type = 0 ) )";
            } else {
                $where .= " AND o.after_verify_status = 2 ";
            }
        }

        //是否发起售后状态
        if( isset($search['after_sale_status']) && $search['after_sale_status'] !== '' && in_array($search['after_sale_status'], [0,1]) ){
            $after_sale_status = intval($search['after_sale_status']);
            $where .= " AND o.after_sale_status = '{$after_sale_status}'";
        }

        //商户名称
        if( !empty($search['merchantUserName']) ) {
            $search['merchantUserName'] = checkFields($search['merchantUserName']);
            $bus = Business::instance()->getMerchantUserListByName($search['merchantUserName']);
            $bus = array_column($bus, 'id');
            if($bus) {
                $ids = implode(",", $bus);
                $where .= " AND o.bid IN ({$ids})";
            }
        }

        //供应商名称
        if( !empty($search['suppplierUserName']) ) {
            $search['suppplierUserName'] = checkFields($search['suppplierUserName']);
            $supplierInfoList = SupplierCompany::instance()->getSupplierListByName($search['suppplierUserName']);
            $supplierIds = array_column($supplierInfoList, 'ID');
            if( $supplierIds ) {
                $ids = implode(",", $supplierIds);
                $where .= " AND o.company_id IN ({$ids})";
            }
        }

        //供应商名称
        if( !empty($search['company_ids']) ) {
            $company_ids = $search['company_ids'];
            if( is_array($company_ids) ) {
                $company_ids = array_filter($company_ids);
                $whereUserIdsIn = implode(",", $company_ids);
                $where .= " AND o.company_id IN ({$whereUserIdsIn})";
            } else {
                $where .= " AND o.company_id = {$company_ids}";
            }
        }

        //订单状态
        if( !empty($search['order_status'])) {
            $order_status = $search['order_status'];
            if( is_array($order_status) ) {
                $whereUserIdsIn = implode(",", $order_status);
                $where .= " AND o.order_status IN ({$whereUserIdsIn})";
            } else {
                $where .= " AND o.order_status = {$order_status}";
            }
        }

        $timestr = Common::getTimeStampParam($search,'o.pay_time','pay_start_time','pay_end_time');
        // 支付时间
        if( $timestr['timeStr'] ) {
            $where.= " AND ".$timestr['timeStr'];
        }

        // 订单创建时间
        $timestr = Common::getTimeStampParam($search,'o.cd','order_start_time','order_end_time');
        if( $timestr['timeStr'] ) {
            $where.= " AND ".$timestr['timeStr'];
        }

        // 订单发货时间
        $timestr = Common::getTimeStampParam($search,'o.express_shipping_time','order_shipping_start_time','order_shipping_end_time');
        if( $timestr['timeStr'] ) {
            $where.= " AND ".$timestr['timeStr'];
        }
        
        //订单售后时间
        $timestr = Common::getTimeStampParam($search,'o.after_sale_time','after_sale_start_time','after_sale_end_time');
        if( $timestr['timeStr'] ) {
            $where.= " AND ".$timestr['timeStr'];
        }

        //订单售后审核时间
        $timestr = Common::getTimeStampParam($search,'o.after_verify_time','after_verify_start_time','after_verify_end_time');
        if( $timestr['timeStr'] ) {
            $where.= " AND ".$timestr['timeStr'];
        }

        //查询商户待结算状态（已发货，未售后）
        if ( isset($search['user_settlement_status']) ) {
            $where .= " AND o.user_settlement_status = 0 AND o.order_status = 2 AND o.after_sale_status=0";
        }

        //查询供应商结算状态（已发货，未售后）
        if ( isset($search['supplier_settlement_status']) ) {
            $where .= " AND o.supplier_settlement_status = 0 AND o.order_status = 2 AND o.after_sale_status=0";
        }
        
        //结算方式
        if(!empty($search['btype']) && !in_array($search['btype'], [1,2])){
            $where.=  " AND b.btype = {$search['btype']}";
        }

        //收货人姓名
        if(!empty($search['receive_name'])){
            $search['receive_name'] = checkFields($search['receive_name']);
            $where.=  " AND o.receive_name = '{$search['receive_name']}'";
        }

        //收货人手机号
        if(!empty($search['recveive_phone'])){
            $search['recveive_phone'] = checkFields($search['recveive_phone']);
            $where.=  " AND o.recveive_phone = '{$search['recveive_phone']}'";
        }

        //精确匹配，查询商户订单编号、供应商订单编号、S2B主（子）订单编号、申报单号、收货人、收货人姓名、运单号、包含商品(综合查询)
        if(!empty($search['synthesize']))
        {
            //综合搜索字段
            $synthesize = $search['synthesize'];
            //包含商品
            $orderGoodsMap = OrderSupplierGoods::instance()->select(['order_id'])->where('goods_name','like',"%{$synthesize}%")->get()->toArray();
            $whereSynthesize = [];
            if($orderGoodsMap){
                $orderIdsStr = join(',',array_unique(array_column($orderGoodsMap,'order_id')));
                $whereSynthesize[] = "o.`id` in ({$orderIdsStr})";
            }

            //商户订单编号
            $whereSynthesize[] = "o.`order_sn` = '{$synthesize}'";
            //供应商订单编号
            $whereSynthesize[] = "o.`supplier_csn` = '{$synthesize}'";
            //供应商订单编号
            $whereSynthesize[] = "o.`thirdpart_order_sn` = '{$synthesize}'";
            //S2B主（子）订单编号
            $whereSynthesize[] = "o.`supplier_dsn` = '{$synthesize}'";
            //申报单号
            $whereSynthesize[] = "o.`supplier_psn` = '{$synthesize}'";
            //收货人手机号码
            $whereSynthesize[] = "o.`recveive_phone` = '{$synthesize}'";
            //收货人姓名
            $whereSynthesize[] = "o.`receive_name` = '{$synthesize}'";
            //运单号
            $whereSynthesize[] = "o.`express_sn` = '{$synthesize}'";
            //合并多条件搜索
            $whereOrderStr = "(" . implode(" OR ", $whereSynthesize) . ")";
            $where.=  " AND {$whereOrderStr}";
        }
        
        //是否发起售后状态
        if( isset($search['order_push_status']) && $search['order_push_status'] !== '' && in_array($search['order_push_status'],['0','1','2']) ){
            $order_push_status = intval($search['order_push_status']);
            $where .= " AND o.order_push_status = '{$order_push_status}'";
        }

        return $where;
    }

    /**
     * 处理加密数据
     * 联系人姓名：只保留第一个字其余星号
                     手机号码：只保留前三位和后三位其余星号
                     身份证号码：前6 和后四  其余星号
                     收货地址：只保留省市区，其余星号
     */
    public function getEncryptDataByOrderItem( $orderItem = [] )
    {
        $user_tag = $orderItem['user_tag'];
        if( !empty($user_tag) && isset($this->encrptUserTag[$user_tag]) )
        {
            //收货人
            if( $orderItem['is_encrypt_order'] == 1 ) {
                $orderItem['receive_name']      = '**********';
                $orderItem['buyer_realname']    = '**********';
                $orderItem['buyer_phone']       = '**********';
                $orderItem['recveive_phone']    = '**********';
                $orderItem['buyer_idcard']      = '**********';
                $orderItem['receive_address']   = '**********';
            } else {
                $orderItem['receive_name']      = mb_substr($orderItem['receive_name'],0,1,"utf-8").LyCrypt::getStrRepeatByMode($orderItem['receive_name'],"*");
                $orderItem['buyer_realname']    = mb_substr($orderItem['buyer_realname'],0,1,"utf-8").LyCrypt::getStrRepeatByMode($orderItem['buyer_realname'],"*");
                $orderItem['buyer_phone']       = mb_substr($orderItem['buyer_phone'],0,3,"utf-8")."*****".mb_substr($orderItem['buyer_phone'],7,3,"utf-8");
                $orderItem['recveive_phone']    = mb_substr($orderItem['recveive_phone'],0,3,"utf-8")."*****".mb_substr($orderItem['recveive_phone'],7,3,"utf-8");
                $length                         = mb_strlen($orderItem['buyer_idcard'],"utf-8");
                $length_repeat                  = $length - 10;
                $orderItem['buyer_idcard']      = substr($orderItem['buyer_idcard'],0,6).str_repeat("*", $length_repeat).substr($orderItem['buyer_idcard'],-4);
                $orderItem['receive_address']   = str_repeat("*", mb_strlen($orderItem['receive_address'],"utf-8"));
            }
        }
        return $orderItem;
    }
}